/**
 * Copyright (C), 2019-2020, 宇信融汇
 * FileName: T1
 * Author:   xbliu
 * Date:     2020/6/23 17:09
 * Description: equals和==对比
 * History:
 * <author>          <time>          <version>          <desc>
 * xbliu           修改时间           版本号              描述
 */
package c_004.abstractDemo;

import java.util.Objects;

/**
 * @Classname T1
 * @Description TODO
 * @Date 2020/6/23 17:09
 * @Created by xbliu
 */
public class T1 {
    private String name;
    private int age;

    public T1() {
    }

    public T1(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        T1 t1 = (T1) o;
        return age == t1.age &&
                Objects.equals(name, t1.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age);
    }

    //自定义类需要重新equals方法
    public static void main(String[] args) {
        T1 t1 = new T1("zhangsan", 20);
        T1 t2 = t1;
        T1 t3 = new T1("zhangsan", 20);
        System.out.println(t1 == t2);
        System.out.println(t1.equals(t2));

        System.out.println(t1 == t3);
        System.out.println(t1.equals(t3));
    }
}
